<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>管理后台</title>
    <link rel="stylesheet/less" href="../../../static/css/index.less"/>
    {#
    <link rel="stylesheet/less" href="../../static/admin/css/user_huafen_record.less"/>
    #}
    <link rel="stylesheet" href="../../../static/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../../static/css/jquery.pagination.css"/>
    <script src="../../../static/js/jquery-1.12.3.js"></script>
    <script src="../../../static/js/less.min.js"></script>
    <script src="../../../static/layui/layui.js"></script>
    <SCRIPT language=javascript src="../../../static/layer/layer.js"></SCRIPT>


</head>
<style>
    .js_w {
        width: 40px;
        height: 25px;
        font-size: 12px;
        line-height: 25px;
    }

    .ll {
        width: 40px;
        height: 25px;
        font-size: 12px;
        line-height: 25px;
    }

    .newadd label {
        padding: 10px 0;
        display: block;
        text-align: left;
    }

    .newadd label .adtitle {
        display: inline-block;
        width: 6rem;
        text-align: right;
        padding-right: 2%;
    }

    .newadd label span {
        text-align: right;
        padding-right: 2%;
    }

    .newadd input {
        padding: 0 10px;
        width: 20%;
        height: 30px;
        line-height: 30px;
        border: 1px solid #dcdcdc;
        border-radius: 5px;
    }

    .newadd select {
        text-align: left;
        padding: 0 5px;
        width: 20%;
        height: 30px;
        line-height: 30px;
        border: 1px solid #dcdcdc;
        border-radius: 5px;
    }

    .subbtn {
        margin-left: 5%;
        padding: 2px 3px;
    }

    .selectTransverse {
        display: inline-block;
    }

    .selectTransverse select {
        width: 30%;
    }
</style>
<body class="layui-layout-body">

{% include "/admin/top.html" %}
{% include "/admin/left.html" %}


<div id="box" class="fl">
    <div class="content" style="height: 100%">
        <div class="content">
            <div class="righthead clearfix">
                <h3 class="title fl" style="color:  #3D89CB">门店新增</h3>
            </div>
            <div class="newadd">

                <label>
                    <span class="adtitle">门店名称</span>
                    <input type="text" id="storeName" class="create">
                </label>
                <label>
                    <span class="adtitle">营业时间</span>
                    <input type="text" id="workTime" class="create">
                </label>


                <label>
                    <span class="adtitle">地址</span>
                    <div class="selectTransverse" data-toggle="distpicker">
                        <select id="province">

                        </select>
                        <select id="city"></select>
                        <select id="county"></select>
                    </div>
                </label>
                <label>
                    <span class="adtitle">详细地址</span>
                    <input id="address" type="text" class="create">
                </label>
                <label>
                    <span class="adtitle">门店照片</span>
                    <input type="file" id="xdaTanFileImg" name="all_file" value=""/>
                    <div class="img-box clearfix" id="imgboxid">
                    </div>
                    <label>
                        <span class="adtitle">选择门店状态</span>
                        <select id="status">
                            <option value="1">营业中</option>
                            <option value="0">筹建中</option>
                            <option value="2">维修中</option>
                        </select>
                    </label>
                </label>
                <button onclick="merchant_edit()" class="subbtn"
                        style="width: 60px;height: 30px;margin-left: 200px;background-color: #3D89CB;float: left">提交
                </button>
            </div>
        </div>
    </div>
</div>
<script src="../../../static/js/distpicker.data.js"></script>
<script src="../../../static/js/distpicker.js"></script>
<script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp&key=LGIBZ-MHFWP-EIUDN-VJXR2-NYS27-6UBQM"></script>
 <script src="../../../static/js/ajaxfileupload.js"></script>
</body>
</html>
<script>
    layui.use('element', function () {
        var element = layui.element;
    });

</script>
<script>
    function merchant_edit() {
        var storeName = $('#storeName').val();
        var workTime = $('#workTime').val();
        var province = $("#province option:selected").val();
        var city = $("#city option:selected").val();
        var area = $("#county option:selected").val();
        var address = $("#address").val();
        var status = $("#status option:selected").val();
        var add = province + ',' + city + ',' + area + ',' + address;
        //对指定地址进行解析
        var geocoder, map, marker = null;
        geocoder = new qq.maps.Geocoder();
        geocoder.getLocation(add);
        //设置服务请求成功的回调函数
        geocoder.setComplete(function (result) {
            var lat = result.detail.location.lat;
            var lng = result.detail.location.lng;
            if (storeName == "" || workTime == "" || status == "" || province == "" || city == "" || area == "" || address == "" || lng == "" || lat == "") {
                layer.msg("类型不能为空");
                return false
            }
            var file = $('#xdaTanFileImg').val()
            if (file == "") {
                layer.msg('请选择照片！');
                return
            }
            $.ajaxFileUpload({
                url: "/admin/store/newly.html",
                'type': 'post',
                data: {
                    'storeName': storeName,
                    'workTime': workTime,
                    'province': province,
                    'city': city,
                    'area': area,
                    'status': status,
                    'address': address,
                    'longitude': lng,
                    'latitude': lat
                },
                secureuri: false,
                fileElementId: 'xdaTanFileImg',
                dataType: 'json',
                success: function (msg) {
                    if (msg.code == 200) {
                        layer.msg("操作成功！", {time: 2000}, function () {
                            window.location.href = "/admin/store/list.html";
                        });
                    } else if (msg.code == 400) {
                        layer.msg("类型已经存在");
                    } else {
                        layer.msg("服务器内部错误！");
                    }
                }
            })
        });
        //若服务请求失败，则运行以下函数
        geocoder.setError(function () {
            alert("出错了，请输入正确的地址！！！");
        });


    }


</script>